package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeFit;
import com.ruoyi.grape.service.IGrapeFitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农事活动适宜性Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/fit")
public class GrapeFitController extends BaseController
{
    @Autowired
    private IGrapeFitService grapeFitService;

    /**
     * 查询农事活动适宜性列表
     */
    @PreAuthorize("@ss.hasPermi('grape:fit:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeFit grapeFit)
    {
        startPage();
        List<GrapeFit> list = grapeFitService.selectGrapeFitList(grapeFit);
        return getDataTable(list);
    }

    /**
     * 导出农事活动适宜性列表
     */
    @PreAuthorize("@ss.hasPermi('grape:fit:export')")
    @Log(title = "农事活动适宜性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeFit grapeFit)
    {
        List<GrapeFit> list = grapeFitService.selectGrapeFitList(grapeFit);
        ExcelUtil<GrapeFit> util = new ExcelUtil<GrapeFit>(GrapeFit.class);
        util.exportExcel(response, list, "农事活动适宜性数据");
    }

    /**
     * 获取农事活动适宜性详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:fit:query')")
    @GetMapping(value = "/{fitId}")
    public AjaxResult getInfo(@PathVariable("fitId") Long fitId)
    {
        return success(grapeFitService.selectGrapeFitByFitId(fitId));
    }

    /**
     * 新增农事活动适宜性
     */
    @PreAuthorize("@ss.hasPermi('grape:fit:add')")
    @Log(title = "农事活动适宜性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeFit grapeFit)
    {
        return toAjax(grapeFitService.insertGrapeFit(grapeFit));
    }

    /**
     * 修改农事活动适宜性
     */
    @PreAuthorize("@ss.hasPermi('grape:fit:edit')")
    @Log(title = "农事活动适宜性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeFit grapeFit)
    {
        return toAjax(grapeFitService.updateGrapeFit(grapeFit));
    }

    /**
     * 删除农事活动适宜性
     */
    @PreAuthorize("@ss.hasPermi('grape:fit:remove')")
    @Log(title = "农事活动适宜性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fitIds}")
    public AjaxResult remove(@PathVariable Long[] fitIds)
    {
        return toAjax(grapeFitService.deleteGrapeFitByFitIds(fitIds));
    }
}
